package 设计模式.factor.pizza.order;

import 设计模式.factor.pizza.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class OrderPizza{
    /*public OrderPizza(){
        Pizza pizza=null;

        String orderType;
        do{
            orderType=getType();
            if (orderType.equals("greek")){
                pizza=new GreekPizza();
                pizza.setName("希腊");
            }else if (orderType.equals("cheese")){
                pizza=new CheesePizza();
                pizza.setName("奶酪");
            }else {
                break;
            }
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        }while (true);
    }*/
    SimpleFactory simpleFactory;
    Pizza pizza=null;
    public OrderPizza(SimpleFactory simpleFactory){
        setFactory(simpleFactory);
    }
    public void setFactory(SimpleFactory simpleFactory){
        String orderType="";
        this.simpleFactory=simpleFactory;
        do {
            orderType=getType();
            pizza=this.simpleFactory.createPizza(orderType);
            if (pizza!=null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
            }
        }while (true);
    }
    private String getType(){
        try {
            BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input 披萨种类");
            String str=strin.readLine();
            return str;
        }catch (IOException e){
            e.printStackTrace();
            return "";
        }
    }
}

